<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {

	public function index(){
        $this->action = U('login');
        $this->theme = C('DEFAULT_THEME');
        $this->display();
    }

    public function login(){
        if(IS_POST){
            $username = I('post.username');
            $password = md5(I('post.password'));
            $userModel = M('user');
            $user = $userModel->where("username='".$username."'")->find();
            if($user['password']==$password){
                session(C('USER_AUTH_KEY'),$user['id']);
                session('USER_AUTH_NAME',$user['name']);
                //获取用户信息
                $userInfo = array();
                session('USER_AUTH_INFO',$userInfo);
                $rbac=new \Org\Util\Rbac();
                $rbac::saveAccessList();
                header('Location:'.U('/Admin/role/index'));
            }else{
                $this->error('用户名或密码错误');
            }
        }
    }

    public function loginOut(){
        session(C('USER_AUTH_KEY'),null);
        session('USER_AUTH_NAME',null);
        session('USER_AUTH_INFO',null);
        header('Location:'.U('/Admin/Login/index'));
    }
}